
Ext.define('Ext.desk.Control.NavigationPanel',{
	extend: 'Ext.view.View',
	alias: 'widget.desknavigationpanel',
	requires:['Ext.window.MessageBox'],
	rootVisible: false,
	itemSelector: 'div.menu-div',
	autoScroll: true,
    emptyText: '没有可显示的菜单',
    initComponent: function () {
        var me = this;
        me.store = Ext.create('Ext.data.Store', {
            fields: ['id','text'],
            proxy: {
                type: 'ajax',
                url: 'menu/getMenu.do',
                extraParams:{
                	node : -7
                },
                reader: {
                    root: 'root'
                }
            },
            autoLoad: true
        });
        
        me.tpl = new Ext.XTemplate(
        	    '<tpl for=".">',
                '<div class="menu-div">',
                  '<span>★&nbsp;{text}</span>',
                '</div>',
            '</tpl>'
        );
        
        me.on('itemclick',function(v,rec){
        	try {
        		var tab = Ext.getCmp('desk-content');
            	var raw = rec.raw;
        		var c = Ext.getCmp('menu-'+raw.link);
        		if(!c){
        			//linktype==1为网络资源
        			if(raw.linktype == 0){
        				c = Ext.create(raw.link,{
            				title: raw.text,
            				ptitle: Ext.getCmp('sys-desk-nav-c').title,
            				icon: raw.icon,
            				closable: true,
            				id: 'menu-'+raw.link
            			});
        			}
        			else{
        				c = Ext.create('Ext.panel.Panel',{
            				title: raw.text,
            				ptitle: Ext.getCmp('sys-desk-nav-c').title,
            				icon: raw.icon,
            				closable: true,
            				id: 'menu-'+raw.link,
            				html : '<iframe width="100%" height="100%" src="'+raw.link+'"></iframe>'
            			});
        			}
        			
        			tab.add(c);
        		}
    			
    			tab.setActiveTab(c);
			} catch (e) {
				// TODO: handle exception
				Ext.Msg.alert('提示','资源<'+raw.text+'>无效,请联系管理员。');
			}
        });
        
        me.callParent();
    }
});